#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > rsp_prop_file.info <<'%EOF%'
   rsp_prop_file
   -----------
   Molecule:         CH2O
   Wave Function:    HF / STO-3G  
   Test Purpose:     Test if correct write to DALTON.PROP from RESPONSE
%EOF%
#######################################################################
#  INTEGRAL INPUT
#######################################################################
cat > rsp_prop_file.mol <<'%EOF%'
ATOMBASIS
CH2O
------------------------
    3              1 1.00D-12
        6.0   1    Basis=STO-3G
C           -1.588367    -.770650     .029109
        8.0   1    Basis=STO-3G
O           -1.657083     .436069    -.009750
        1.0   2    Basis=STO-3G
H           -.620668   -1.294822      .054251
H           -2.508043   -1.382001     .040282
%EOF%
#######################################################################
#  DALTON INPUT
#######################################################################
cat > rsp_prop_file.dal <<'%EOF%'
**DALTON
.RUN RESPONSE
**INTEGRALS
.DIPLEN
**WAVE FUNCTIONS
.HF
*SCF INPUT
.THRESH
1.0D-12
.PRINT
 3
**RESPONSE
*LINEAR
.DIPLEN
.THCLR
1.0D-9
**END OF DALTON INPUT
%EOF%
#
#######################################################################
#  CHECK SCRIPT
#######################################################################
#
echo $CHECK_SHELL >rsp_prop_file.check
cat >>rsp_prop_file.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

#
# Test af Energy
#

CRIT1=`$GREP "#  1 1 ENERGY   Ground state Energy =    * \-112\.353697509" $log | wc -l`
TEST[1]=`expr $CRIT1 ` 
CTRL[1]=1
ERROR[1]="ENERGY NOT CORRECTLY WRITTEN TO PROPERTY FILE"

#
# Test of HF polarizability
#
CRIT1=`$GREP " #  2 1 * <<XDIPLEN ,XDIPLEN >>\( ( |0)\.000000\) =  *     2\.461169" $log | wc -l`
CRIT2=`$GREP " #  3 1 * <<XDIPLEN ,YDIPLEN >>\( ( |0)\.000000\) =  *    0*\.00000" $log | wc -l`
CRIT3=`$GREP " #  4 1 * <<XDIPLEN ,ZDIPLEN >>\( ( |0)\.000000\) =  *    0*\.00000" $log | wc -l`
CRIT4=`$GREP " #  5 1 * <<YDIPLEN ,YDIPLEN >>\( ( |0)\.000000\) =  *     6\.184500" $log | wc -l`
CRIT5=`$GREP " #  6 1 * <<YDIPLEN ,ZDIPLEN >>\( ( |0)\.000000\) =  *  \-0*\.016158" $log | wc -l`
CRIT6=`$GREP " #  7 1 * <<ZDIPLEN ,ZDIPLEN >>\( ( |0)\.000000\) =  *    10\.308181" $log | wc -l`
TEST[2]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 `
CTRL[2]=6
ERROR[2]="HF POLARZABILITY NOT CORRECTLY WRITTEN TO PROPERTY FILE"

PASSED=1 
for i in 1 2 
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi                
%EOF%
chmod +x rsp_prop_file.check
#######################################################################
